
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @module data.session
* @author: Hjava
* @description: 透传模块消息外包
* @since: 2018-07-22 14:35:47
*/
var data_constant_1 = __webpack_require__(/*! _data/data.constant */ "./src/core/data/data.constant.ts");
var protocol_1 = __webpack_require__(/*! _util/protocol */ "./src/core/utils/protocol.ts");
var bufferType_1 = __webpack_require__(/*! _util/bufferType */ "./src/core/utils/bufferType.ts");
var deviceInfo_1 = __webpack_require__(/*! _util/deviceInfo */ "./src/core/utils/deviceInfo.ts");
var byteBuffer_1 = __webpack_require__(/*! _util/byteBuffer */ "./src/core/utils/byteBuffer.ts");
var userData_1 = __webpack_require__(/*! _util/userData */ "./src/core/utils/userData.ts");
var timer_1 = __webpack_require__(/*! _util/timer */ "./src/core/utils/timer.ts");
var uuid_1 = __webpack_require__(/*! _util/uuid */ "./src/core/utils/uuid.ts");
var DataSession = {};
DataSession.DataSendReq = protocol_1.default.Response.extend({
    category: 'DATA',
    uri: data_constant_1.default.DATA.URI_DATA_SEND_REQ,
    init: function () {
        this.type = 0; // 业务类型
        this.msgId = 0;
        this.data = []; //用户数据，Web SDK默认为string类型
        this.channel = 0;
        this.deviceId = userData_1.default.get('deviceId');
    },
    marshall: function () {
        this.push(this.type);
        this.push(this.msgId, bufferType_1.default.LONG);
        typeof this.data === 'string' ? this.push(byteBuffer_1.default.strToBytes(this.data), bufferType_1.default.BYTES) : this.push(this.data, bufferType_1.default.BYTES);
        this.push(this.channel, bufferType_1.default.SHORT);
        this.push(this.deviceId, bufferType_1.default.STRING);
    },
    unmarshall: function () {
        this.type = this.popInt();
        this.msgId = this.popLong().value();
        var buffer = this.popBytes();
        this.data = (new byteBuffer_1.default(buffer)).readUTF8String(buffer.byteLength);
        this.channel = this.popShort();
        this.deviceId = this.popString();
    }
});
DataSession.DataSendAck = protocol_1.default.Response.extend({
    category: 'DATA',
    uri: data_constant_1.default.DATA.URI_DATA_ACK,
    init: function () {
        this.uid = '';
        this.messageIds = [];
        this.type = 0;
        this.deviceType = deviceInfo_1.default.deviceType;
        this.data = [];
        this.deviceId = userData_1.default.get('deviceId');
    },
    marshall: function () {
        this.push(this.uid, bufferType_1.default.LONG);
        this.push(this.messageIds, bufferType_1.default.ARRAY_LONG);
        this.push(this.type, bufferType_1.default.INT);
        this.push(this.deviceType, bufferType_1.default.BYTE);
        this.push(this.data, bufferType_1.default.BYTES);
        this.push(this.deviceId, bufferType_1.default.STRING);
    },
    unmarshall: function () {
        this.uid = this.popLong().value();
        this.messageIds = this._popArrayLong();
        this.type = this.popInt();
        this.deviceType = this.popByte();
        this.data = this.popBytes();
        this.deviceId = this.popString();
    }
});
DataSession.DataSendClientReq = protocol_1.default.Response.extend({
    category: 'DATA',
    uri: data_constant_1.default.DATA.URI_DATA_SEND_CLIENT_REQ,
    init: function () {
        this.uri = data_constant_1.default.DATA.URI_DATA_SEND_CLIENT_REQ;
        this.fromUid = 0;
        this.messageId = 0;
        this.cts = timer_1.default.get();
        this.type = 0; // 业务类型, 对应于PDataSendReq中的type
        this.deviceType = deviceInfo_1.default.deviceType;
        this.data = [];
        this.messageUuid = uuid_1.default.next();
        // 频道
        this.channel = 0;
        // 消息来源设备Id
        this.deviceId = userData_1.default.get('deviceId');
    },
    marshall: function () {
        this.push(this.fromUid, bufferType_1.default.LONG);
        this.push(this.messageId, bufferType_1.default.LONG);
        this.push(this.cts, bufferType_1.default.LONG);
        this.push(this.type, bufferType_1.default.INT);
        this.push(this.deviceType, bufferType_1.default.BYTE);
        typeof this.data === 'string' ? this.push(byteBuffer_1.default.strToBytes(this.data), bufferType_1.default.BYTES) : this.push(this.data, bufferType_1.default.BYTES);
        this.push(this.messageUuid, bufferType_1.default.STRING);
        this.push(this.channel, bufferType_1.default.SHORT);
        this.push(this.deviceId, bufferType_1.default.STRING);
    },
    unmarshall: function () {
        this.fromUid = this.popLong().value();
        this.messageId = this.popLong().value();
        this.cts = this.popLong().value();
        this.type = this.popInt();
        this.deviceType = this.popByte();
        var buffer = this.popBytes();
        this.data = (new byteBuffer_1.default(buffer)).readUTF8String(buffer.byteLength);
        this.messageUuid = this.popString();
        this.channel = this.popShort();
        this.deviceId = this.popString();
    }
});
exports.default = DataSession;


//# sourceURL=webpack://MTDX/./src/core/data/data.session.ts?